package android.slc.box.core.utils


class DpUtils(private val windowSize: Int? = null) {
    companion object {
        const val CMS_SCREEN_SIZE = 411.0
        private val WINDOW_MAX_SIZE = ViewUtils.getAppWindowMaxWidth().coerceAtMost(ViewUtils.getAppWindowMaxHeight())
    }

    private fun getWindowSize(): Double {
        return windowSize?.toDouble() ?: WINDOW_MAX_SIZE
    }

    private fun getPxScale(): Double {
        return getWindowSize() / CMS_SCREEN_SIZE
    }

    private fun getDpScale(): Double {
        return CMS_SCREEN_SIZE / getWindowSize()
    }

    fun dp2Px(value: Int): Double {
        return String.format("%.2f", (value * getPxScale())).toDouble()
    }

    fun dp2Px(value: Float): Double {
        return String.format("%.2f", (value * getPxScale())).toDouble()
    }

    fun dp2Px(value: Double): Double {
        return String.format("%.2f", (value * getPxScale())).toDouble()
    }

    fun px2Dp(value: Int): Double {
        return String.format("%.2f", (value * getDpScale())).toDouble()
    }

    fun px2Dp(value: Float): Double {
        return String.format("%.2f", (value * getDpScale())).toDouble()
    }

    fun px2Dp(value: Double): Double {
        return String.format("%.2f", (value * getDpScale())).toDouble()
    }
}
